#ifndef _LIB_UTILS
#define _LIB_UTILS

// Trims whitespace off strings
String.prototype.trim = function() {
	return this.replace(/^\s*|\s*$/g, '');
};

// Get element by ID
function $i( id, context ) {
	return (context || document).getElementById( id );
}

// Iterate over a xpath query
function $xp_each( xpath, fn, context ) {
	context = context || document;
	var doc = context.evaluate ? context : ( context.ownerDocument ? context.ownerDocument : document ),
		xpath = doc.evaluate( xpath, context, null, 7, null );
	for ( var i = 0, element; element = xpath.snapshotItem( i ); i++ )
		fn( element, i, xpath );
	xpath = null;
}
#endif